﻿<!DOCTYPE html>
<html>
<head>
	<title>监控平台</title>
	<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script>
	<!-- <script src="js/jquery-1.11.3.js"></script> -->
	<script>


	function funcTest(){
    //每隔3秒执行一次timelyFun方法
    	console.log(1);
	    window.setInterval("getApiJson()",60000);
	}
	nowExpect = 0;
	window.onload = funcTest;
	//每隔指定时间请求一次接口，并处理相应逻辑
	function getApiJson() {
		  $.ajax({
		    async: false,
		    type: "GET",
		    dataType: 'jsonp',
		    jsonp: 'callback',
		    jsonpCallback: 'callbackfunction',
		    url: "http://f.apiplus.net/cqssc.json",
		    data: "",
		    timeout: 3000,
		    contentType: "application/json;utf-8",
		    success: function(msg) {
		    	//请求api成功，将获取的字符串分隔成数组，方便遍历计算
			    openCode = msg.data[0]['opencode'];

			    // console.log(msg.data[0]['expect']);
			    openCodeArray = openCode.split(",");
			    //如果第1,3,5位数的和 等于第2,4的和进行处理
			    if (msg.data[0]['expect'] == nowExpect) {
			    	return true;
			    }
			    for (var i = 0; i < openCodeArray.length; i++) {
			    	openCodeArray[i] = parseInt(openCodeArray[i]);
			    } 
			    var total135 = openCodeArray[0]+openCodeArray[2]+openCodeArray[4]; 
			    console.log(total135);
			    var total24 = openCodeArray[1]+openCodeArray[3]; 
			    console.log(total24);
			    if (total135==total24) {
			    	$("#openCodeInfo").html($("#openCodeInfo").html()+"\n"+msg.data[0]['expect']+"\t"+msg.data[0]['opencode']+"\t归零");
			    }else{
			    	var differ = total135 - total24;
			    	$("#openCodeInfo").html($("#openCodeInfo").html()+"\n"+msg.data[0]['expect']+"\t"+msg.data[0]['opencode']+"\t"+differ);
			    }
			    //记录当前期数
			    nowExpect = msg.data[0]['expect'];
		    }
		  });	
	}
	</script>
</head>
<body>
	<p class="status">运行状态:运行中</p>

	<textarea class="info" id="openCodeInfo"></textarea>
</body>
</html>
<style type="text/css">
	.info{
		width: 80%;
		height: 300px;
	}
</style>